home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Arrays / ConstArrayOf.cp < prev    next >
Text File  |  1997-06-28  |  3KB  |  127 lines

  1. // ConstArrayOf.cp
  2.  
  3. #ifndef ConstArrayOf_h
  4. #include "ConstArrayOf.h"
  5. #endif
  6. #ifndef MinMax_h
  7. #include "MinMax.h"
  8. #endif
  9.  
  10. template < class Element >
  11. ConstArrayOf<Element> ConstArrayOf<Element>::Head( uint32 size ) const
  12.   {
  13.     Assert( !Null() );
  14.     Assert( size <= length );
  15.     return ConstArrayType( start, size );
  16.   }
  17.  
  18. template < class Element >
  19. ConstArrayOf<Element> ConstArrayOf<Element>::Tail( uint32 position ) const
  20.   {
  21.     Assert( !Null() );
  22.     Assert( position <= length );
  23.     return ConstArrayType( start + position, length - position );
  24.   }
  25.  
  26. template < class Element >
  27. ConstArrayOf<Element> ConstArrayOf<Element>::Middle( URange32 range ) const
  28.   {
  29.     Assert( !Null() );
  30.     Assert( range.End() <= length );
  31.     return ConstArrayType( start + range.Start(), range.Length() );
  32.   }
  33.  
  34. template < class Element >
  35. void ConstArrayOf<Element>::Truncate( uint32 position )
  36.   {
  37.     Assert( !Null() );
  38.     Assert( position <= length )
  39.     length = position;
  40.   }
  41.  
  42. template < class Element >
  43. void ConstArrayOf<Element>::Shorten( uint32 amount )
  44.   {
  45.     Assert( !Null() );
  46.     Assert( amount <= length );
  47.     start += amount;
  48.     length -= amount;
  49.   }
  50.  
  51. template < class Element >
  52. void ConstArrayOf<Element>::Append( ConstArrayType tail )
  53.   {
  54.     Assert( !Null() );
  55.     Assert( Precedes( tail ) );
  56.     length += tail.length;
  57.   }
  58.  
  59. template < class Element >
  60. ConstArrayOf<Element> ConstArrayOf<Element>::operator+( ConstArrayType tail ) const
  61.   {
  62.     ConstArrayType result( *this );
  63.     result += tail;
  64.     return result;
  65.   }
  66.  
  67. template < class Element >
  68. void ConstArrayOf<Element>::Prepend( ConstArrayType head )
  69.   {
  70.     Assert( !Null() );
  71.     Assert( Follows( head ) );
  72.     start = head.start;
  73.     length += head.length;
  74.   }
  75.  
  76. template < class Element >
  77. bool ConstArrayOf<Element>::operator<=( ConstArrayType r ) const
  78.   {
  79.     return start >= r.start && End() <= r.End();
  80.   }
  81.  
  82. template < class Element >
  83. bool ConstArrayOf<Element>::operator<( ConstArrayType r ) const
  84.   {
  85.     return *this <= r && *this != r;
  86.   }
  87.  
  88. template < class Element >
  89. bool ConstArrayOf<Element>::IsHeadOf( ConstArrayType r ) const
  90.   {
  91.     return start == r.start && length <= r.length;
  92.   }
  93.  
  94. template < class Element >
  95. bool ConstArrayOf<Element>::IsTailOf( ConstArrayType r ) const
  96.   {
  97.     return End() == r.End() && length <= r.length;
  98.   }
  99.  
  100. template < class Element >
  101. bool ConstArrayOf<Element>::Touches( ConstArrayType r ) const
  102.   {
  103.     return End() >= r.start && start <= r.End();
  104.   }
  105.  
  106. template < class Element >
  107. ConstArrayOf<Element> ConstArrayOf<Element>::operator&( ConstArrayType r ) const
  108.   {
  109.     Assert( !Null() );
  110.     Assert( !r.Null() );
  111.     Assert( Touches( r ) );
  112.     const Element *lastStart = Max( start, r.start );
  113.     const Element *firstEnd = Min( End(), r.End() );
  114.     return ConstArrayType( lastStart, firstEnd - lastStart );
  115.   }
  116.  
  117. template < class Element >
  118. ConstArrayOf<Element> ConstArrayOf<Element>::operator|( ConstArrayType r ) const
  119.   {
  120.     Assert( !Null() );
  121.     Assert( !r.Null() );
  122.     Assert( Touches( r ) );
  123.     const Element *firstStart = Min( start, r.start );
  124.     const Element *lastEnd = Max( End(), r.End() );
  125.     return ConstArrayType( firstStart, lastEnd - firstStart );
  126.   }
  127.